package com.qqt.csr.common.enums;

import lombok.Getter;

@Getter
public enum FileTypeEnum {
    GIF(FileGroupEnum.IMG, "001", "gif", "image/gif"),
    JPEG(FileGroupEnum.IMG, "002", "jpeg", "image/jpeg"),
    JPG(FileGroupEnum.IMG, "003", "jpg", "image/jpeg"),
    PNG(FileGroupEnum.IMG, "004", "png", "image/png"),
    ico(FileGroupEnum.IMG, "005", "ico", "image/x-icon"),

    DOC(FileGroupEnum.DOC, "101", "doc", "application/msword"),
    DOCX(FileGroupEnum.DOC, "102", "docx", "application/msword"),
    PDF(FileGroupEnum.DOC, "103", "pdf", "application/pdf"),
    PPTX(FileGroupEnum.DOC, "104", "pptx", "application/x-ppt"),
    PPT(FileGroupEnum.DOC, "105", "ppt", "application/x-ppt"),
    MD(FileGroupEnum.DOC, "106", "md", "application/octet-stream"),
    XLSX(FileGroupEnum.DOC, "107", "xlsx", "application/x-xls"),
    XLS(FileGroupEnum.DOC, "108", "xls", "application/x-xls"),
    CSV(FileGroupEnum.DOC, "109", "csv", "text/csv"),
    TXT(FileGroupEnum.DOC, "110", "txt", "text/plain"),
    ;

    private final FileGroupEnum group;
    private final String type;
    private final String ext;
    private final String contentType;

    FileTypeEnum(FileGroupEnum group, String type, String ext, String contentType) {
        this.group = group;
        this.type = type;
        this.ext = ext;
        this.contentType = contentType;
    }

    public static FileTypeEnum of(String ext) {
        for (FileTypeEnum fileTypeEnum : FileTypeEnum.values()) {
            if (fileTypeEnum.getExt().equalsIgnoreCase(ext)) {
                return fileTypeEnum;
            }
        }
        return null;
    }
}
